<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ page import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.io.PrintWriter" %>

<%
String productName = request.getParameter("productName");
double price = Double.parseDouble(request.getParameter("price"));
String description = request.getParameter("description");

Connection connection = null;
Statement statement = null;

try {
    Class.forName("org.mariadb.jdbc.Driver");
    connection = DriverManager.getConnection("jdbc:mariadb://10.220.140.102:3366/studb14", "stu14", "jyw745DJ");
    statement = connection.createStatement();
    String query = "INSERT INTO db_order (productname, price, introduce) VALUES ('" + productName + "', " + price + ", '" + description + "')";
    statement.executeUpdate(query);
    out.println("菜品成功添加到数据库！");
} catch (SQLException e) {
    out.println("发生错误： " + e.getMessage());
} finally {
    try {
        if (statement != null) {
            statement.close();
        }
        if (connection != null) {
            connection.close();
        }
    } catch (SQLException ex) {
        out.println("关闭连接时发生错误： " + ex.getMessage());
    }
}
%>
</body>
</html>